package com.demo.datastructure.reorder.insertionSort;

import com.demo.datastructure.reorder.Example;

/**
 * @author ljr
 * @version 1.0
 * @description: 插入排序
 * @date 2021/9/23 21:38
 */
public class SimpleInsertSort4 implements Example {

    @Override
    public void sort(Comparable[] a) {
        int n = a.length;
        for(int i = 1; i < n; i++){
            int l = i - 1;
            Comparable val = a[i];
            for(; l > -1; l--){
                if(less(a[l], val)){
                    break;
                }
                a[l+1] = a[l];
            }
            a[l+1] = val;
        }
    }
}
